package com.ruoyi.carowner.service.impl;

import java.util.List;

import com.ruoyi.carowner.domain.CarownerWallet;
import com.ruoyi.carowner.service.ICarownerWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.carowner.mapper.CarownerWxpayMapper;
import com.ruoyi.carowner.domain.CarownerWxpay;
import com.ruoyi.carowner.service.ICarownerWxpayService;

/**
 * 车主微信支付Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-19
 */
@Service
public class CarownerWxpayServiceImpl implements ICarownerWxpayService {
    @Autowired
    private CarownerWxpayMapper carownerWxpayMapper;

    @Autowired
    private ICarownerWalletService carownerWalletService;
    /**
     * 查询车主微信支付
     *
     * @param id 车主微信支付主键
     * @return 车主微信支付
     */
    @Override
    public CarownerWxpay selectCarownerWxpayById(Integer id) {
        return carownerWxpayMapper.selectCarownerWxpayById(id);
    }

    @Override
    public CarownerWxpay selectWxpayByUserId(Integer user_id) {
        return carownerWxpayMapper.selectWxpayByUserId(user_id);
    }

    /**
     * 查询车主微信支付列表
     *
     * @param carownerWxpay 车主微信支付
     * @return 车主微信支付
     */
    @Override
    public List<CarownerWxpay> selectCarownerWxpayList(CarownerWxpay carownerWxpay) {
        return carownerWxpayMapper.selectCarownerWxpayList(carownerWxpay);
    }

    /**
     * 新增车主微信支付
     *
     * @param carownerWxpay 车主微信支付
     * @return 结果
     */
    @Override
    public int insertCarownerWxpay(CarownerWxpay carownerWxpay) {
        return carownerWxpayMapper.insertCarownerWxpay(carownerWxpay);
    }

    /**
     * 修改车主微信支付
     *
     * @param carownerWxpay 车主微信支付
     * @return 结果
     */
    @Override
    public int updateCarownerWxpay(CarownerWxpay carownerWxpay) {

        CarownerWallet carownerWallet = carownerWalletService.selectCarownerWalletById(carownerWxpay.getId());
        carownerWallet.setBalance(carownerWallet.getBalance() + carownerWxpay.getPaymoney());
        carownerWallet.setPaymoney(carownerWxpay.getPaymoney());
        carownerWallet.setPaytype(0);
        carownerWallet.setUserId(carownerWxpay.getUserId());
        carownerWallet.setTransstatus(0);
        carownerWalletService.updateCarownerWallet(carownerWallet);

        return carownerWxpayMapper.updateCarownerWxpay(carownerWxpay);
    }

    /**
     * 批量删除车主微信支付
     *
     * @param ids 需要删除的车主微信支付主键
     * @return 结果
     */
    @Override
    public int deleteCarownerWxpayByIds(Integer[] ids) {
        return carownerWxpayMapper.deleteCarownerWxpayByIds(ids);
    }

    /**
     * 删除车主微信支付信息
     *
     * @param id 车主微信支付主键
     * @return 结果
     */
    @Override
    public int deleteCarownerWxpayById(Integer id) {
        return carownerWxpayMapper.deleteCarownerWxpayById(id);
    }
}
